﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;
using System.Web.Mvc;

namespace MyHealthByDesignWebsite.Models
{
    public class MyHealthMeasModelView
    {
        //Description:  Model View for health Measurements
        //Created:  Nov 2011
        //Programmer:  Bob Whiteis

        // Properties
        public NutritionProfile np { get; private set; }
        public HealthProfile hp { get; private set; }
        public ActivityLevel al = new ActivityLevel();
        public IEnumerable<SelectListItem> ViewBag;

        // Constructor
        //pre-condition:  Nutrition Profile and Health Profile have been supplied
        //post-condtion Health Measurement Model View has been created
        public MyHealthMeasModelView(NutritionProfile npIn, HealthProfile hpIn)
        {
             hp = hpIn;
             np = npIn;

             ActivityLevel al = new ActivityLevel();
             //get activity
             ViewBag = al.items();
        }

      
        //pre-condition:  Health Measure information has been submitted
        //post-condtion: false hase been return if there are any validation issues
        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }

        public bool Validate()
        {
            if (!this.IsValid)
                return false;
            else
                return true;
        }

        //pre-condition:  Health Measure information has been submitted
        //post-condtion: lsit of rules violations has been returned
        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (np.NP_heightFt <= 0 || np.NP_heightFt == null)
                yield return new RuleViolation("Height must be greater than zero.", "NP_heightFt");
            if (np.NP_heightIn <= 0 || np.NP_heightFt != null)
                yield return new RuleViolation("Height must be greater than zero.", "NP_heightFt");
            if (np.NP_weight <= 0 || np.NP_weight == null)
                yield return new RuleViolation("Weight must be greater than zero", "NP_weight");
            yield break;
        }


    }
}